package com.xzlf.controller;

import com.xzlf.domain.NovelChapter;
import com.xzlf.domain.WebSite;
import com.xzlf.service.NovelChapterService;
import com.xzlf.service.WebSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("/templates/client")
@Controller
public class ClientController {

    @Autowired
    private NovelChapterService novelChapterService;

    @Autowired
    private WebSiteService webSiteService;

    @GetMapping("/showContent")
    public String showContent(String url, int pid, int id, Model model){
        NovelChapter novelChapter = novelChapterService.getById(id);
        if ("next".equals(url)){
            WebSite webSite = webSiteService.getById(pid);
            novelChapter.setContentUrl(webSite.getUrl()+novelChapter.getUri());
            url = novelChapter.getContentUrl();
        }
        String html = novelChapterService.getContent(url, pid);
        model.addAttribute("html", html);
        model.addAttribute("novelChapter", novelChapter);
        return "client/novelChapter";
    }
}
